import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_home_manager/pages/Home/index.dart';
import 'package:flutter_home_manager/pages/MIne/index.dart';

class TabsPage extends StatefulWidget {
  TabsPage({Key? key}) : super(key: key);

  @override
  _TabsPageState createState() => _TabsPageState();
}

class _TabsPageState extends State<TabsPage> {
  int currentIndex = 0;
  List tabList = [
    {
      "label": "首页",
      "icon": "assets/tabs/home_default.png",
      "activeIcon": "assets/tabs/home_active.png",
    },
    {
      "label": '我的',
      "icon": "assets/tabs/my_default.png",
      "activeIcon": "assets/tabs/my_active.png",
    }
  ];

//底部tab栏的列表
  List<BottomNavigationBarItem> getTabsBar() {
//首页和我的 tabs
    List<BottomNavigationBarItem> tabsList = [];
    for (var i = 0; i < tabList.length; i++) {
      tabsList.add(
        BottomNavigationBarItem(
            icon: Image.asset(tabList[i]["icon"], width: 30, height: 30),
            activeIcon:
                Image.asset(tabList[i]["activeIcon"], width: 30, height: 30),
            label: tabList[i]["label"]),
      );
    }
    return tabsList;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
          child: IndexedStack(
        index: currentIndex,
        children: [
          HomeView(),
          MinView(),
        ],
      )),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: currentIndex,
        onTap: (index) {
          currentIndex = index;
          setState(() {});
        },
        items: getTabsBar(),
      ),
    );
  }
}
